package com.lwgk.mvp.fragmentview;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.zxing.common.StringUtils;
import com.lwgk.R;
import com.lwgk.compinterface.OnMultiClickListener;
import com.lwgk.mvp.fragmentmodel.HomeFragmentPresenter;
import com.lwgk.mvp.presenter.HomeFragmentPrecenterImpl;
import com.lwgk.mvp.presenter.HomeFragmentView;
import com.lwgk.mvp.view.LoginActivity;
import com.lwgk.utils.AppManagerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

/**
 * created by 赵航
 * 联系微信 微信号：zhao--hang--
 * on 2019/7/17
 * --------------------------------------------------------------------------
 * 描述： 首页的home界面,包含行测和申论
 * 注意事项：设置初始化为有网有数据的状态
 */
public class HomeFragment extends Fragment implements HomeFragmentView {
    private View                      mHomeFragment;
    private HomeFragmentPrecenterImpl mPrecenter;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mPrecenter = new HomeFragmentPresenter(HomeFragment.this);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mHomeFragment = inflater.inflate(R.layout.fragment_home, null);
        initView(mHomeFragment);
        initData();
        return mHomeFragment;
    }

    private void initView(View prentView) {
        OkGo.<String>post("https://www.932edu.com/courseSys_test/app/basicdata/all")
                .headers("token", "0a0f9b5a104048fb888261b0e91a363b")
//                .params("pageSize", 1 + "")
//                .params("sbt", 0 + "")
//                .params("subject", 0)
                .params("", "")
                .cacheMode(CacheMode.REQUEST_FAILED_READ_CACHE)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
//                        Intent intent = new Intent();
//                        AppManagerUtils.getInstance().finishTopActivity();
//                        intent.setClass(getContext(), LoginActivity.class);
//                        startActivity(intent);
                        System.out.println("请正常获取的数据"+response.code());
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        System.out.println("请求错误的数据"+response.code());
                    }

                    @Override
                    public void onCacheSuccess(Response<String> response) {
                        super.onCacheSuccess(response);
                        System.out.println("这个缓存数据"+response.body());
                    }
                });
        //增加数据库
        prentView.findViewById(R.id.updata).setOnClickListener(new OnMultiClickListener() {
            @Override
            public void onMultiClick(View v) {

            }
        });
        //删除数据库
        prentView.findViewById(R.id.delete).setOnClickListener(new OnMultiClickListener() {
            @Override
            public void onMultiClick(View v) {
            }
        });
        //修改数据库
        prentView.findViewById(R.id.fixtData).setOnClickListener(new OnMultiClickListener() {
            @Override
            public void onMultiClick(View v) {
            }
        });
        //查询数据库
        prentView.findViewById(R.id.search).setOnClickListener(new OnMultiClickListener() {
            @Override
            public void onMultiClick(View v) {
            }
        });


    }

    private void initData() {
        //处理业务逻辑
        //        mPrecenter.
    }
}
